import { setToken, getToken, http,clearToken } from '@/utils'
import { makeAutoObservable } from 'mobx'
class loginStore {
  token = getToken() || ''
  constructor() {
    //响应式
    makeAutoObservable(this)
  }
  login = async ({ mobile, code }) => {
    //调用登录接口
    const res = await http.post('http://geek.itheima.net/v1_0/authorizations', {
      mobile,
      code,
    })
    //存入token
    this.token = res.data.token
    setToken(res.data.token)
  }
   // 退出登录
   loginOut = () => {
    this.token = ''
    clearToken()
  }
}

export default loginStore
